﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eShop.Business;

public partial class product_search : SitePublicBasePage
{
    public int PageSize { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            productList.ShowPaging = true;
            PageSize = 50;
            productList.PageIndexChanged += new controls_product_list.PageIndexChangedHandler(productList_PageIndexChanged);
            BindProducts(1, PageSize);
        }
    }

    void productList_PageIndexChanged(int selectedPageIndex)
    {
        BindProducts(selectedPageIndex, PageSize);
    }

    private void BindProducts(int pageIndex, int pageSize)
    {
        productList.SelectedPageIndex = pageIndex;
        productList.PageSize = pageSize;
        productList.TotalItemCount = ProductManager.SearchByBothNameCount(SessionManager.SearchKeyword, SessionManager.SearchKeyword, SearchType.SearchByItemNumberAndKeyword);

        productList.DataSource = ProductManager.SearchByBothName(pageIndex, pageSize, SessionManager.SearchKeyword, SessionManager.SearchKeyword, SearchType.SearchByItemNumberAndKeyword);
        productList.DataBind();
    }
}